package mwt.xml.xdbforms.xforms.impl;

import java.util.HashMap;
import java.util.Map;
import mwt.xml.xdbforms.dbms.exceptions.TypeNotFoundException;
import mwt.xml.xdbforms.xforms.UIHandler;

public class MySQLUIHandler implements UIHandler {
    private Map<String, String> map = new HashMap<String, String>(24);

    public MySQLUIHandler (){
        this.map.put("varchar", "xf:input");
        this.map.put("int", "xf:input");
        this.map.put("int unsigned", "xf:input");
        this.map.put("tinyint", "xf:input");
        this.map.put("text", "xf:textarea");
        this.map.put("date", "xf:input");
        this.map.put("smallint", "xf:input");
        this.map.put("mediumint", "xf:input");
        this.map.put("float", "xf:input");
        this.map.put("double", "xf:input");
        this.map.put("decimal", "xf:input");
        this.map.put("datetime", "xf:input");
        this.map.put("timestamp", "xf:input");
        this.map.put("time", "xf:input");
        this.map.put("year", "xf:input");
        this.map.put("char", "xf:input");
        this.map.put("tinyblob", "xf:input");
        this.map.put("tinytext", "xf:input");
        this.map.put("blob", "xf:input");
        this.map.put("mediumblob", "xf:input");
        this.map.put("mediumtext", "xf:input");
        this.map.put("longblob", "xf:input");
        this.map.put("bit", "xf:input");
        this.map.put("tinyint", "xf:input");
        this.map.put("binary", "xf:input");
        this.map.put("bigint", "xf:input");
        this.map.put("bool", "xf:input");
        this.map.put("longtext", "xf:textarea");
    }

    public String getUIElement(String typeName) throws TypeNotFoundException {
        typeName = typeName.toLowerCase();
        if (!this.map.containsKey(typeName)) {
            throw new TypeNotFoundException("Il tipo " + typeName + " non è gestito!");
        }

        return this.map.get(typeName);
    }

}
